package member

import (
	"parking-lot-go-dingding/controller"
	"parking-lot-go-dingding/model/dingtalk/system"

	"github.com/gin-gonic/gin"
)

func DingTalkUser(c *gin.Context) {
	corpId := c.Query("corp_id")

	var dingtalkSystemDepartmentUserStruct system.DingtalkSystemDepartmentUserStruct
	dingtalkSystemDepartmentUserList, err := dingtalkSystemDepartmentUserStruct.List(map[string]interface{}{
		"corp_id": corpId,
	})

	if err != nil {
		controller.Fail(c, "数据获取失败"+err.Error())
	}

	userReturn := make([]map[string]interface{}, 0)

	for _, v := range dingtalkSystemDepartmentUserList {
		userReturn = append(userReturn, map[string]interface{}{
			"userid":    v.Userid,
			"dept_id":   v.DepartmentId,
			"dept_name": v.DepartmentName,
			"name":      v.Name,
			"title":     v.Title,
		})
	}

	controller.Success(c, userReturn)
}
